package cn.edu.swu.lzr.Safe;


import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.OutputStream;


public class Codeservlet extends HttpServlet {
        public final static String Code = "Auth_Code";

        public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
        {
                CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(100,50,4,30);
                String code = captcha.getCode();
                request.getSession(true ).setAttribute(Code,code);

                try (OutputStream outputStream = response.getOutputStream()){
                        captcha.write(outputStream);
                }

        }
}
